
#ifndef _MEMBER_BHTMLWIDGET_H_
#define _MEMBER_BHTMLWIDGET_H_

#include <ctime>
#include <BLine2>
#include <BMap>
#include <BStyle>
#include <BXmlNode>
#include <BHtmlWidget>
#include "IHtmlStyle.h"

#define html_member(html)			((member_BHtmlWidget*)((BHtmlWidget*)html)->_ptr)

namespace BWE
{
	class member_BHtmlWidget : public BObject
	{
		friend class BHtmlWidget;
	public:
		member_BHtmlWidget(BHtmlWidget* htmlWidget);
		~member_BHtmlWidget();

		void initStyle();
		void initHead();
		void loadResource(BHtmlItem* item);
		void freshStyle();
		void freshPageArea();
		void dispenseUpperStyle(BHtmlItem* item, BHtmlItem* upper);
		void freshStyle(BHtmlItem* item);
		BLine2 inputLine();

		void paintItem(BHtmlItem* item, BPainter& painter);
		void paintFloatItem(BHtmlItem* item, BPainter& painter);

		bool selectItems();
		bool removeSelection();

		void itemTextEdited(BHtmlItem* item);

		BHtmlItem* findItem(const BPoint& pos);
		BHtmlItem* findItem(const BPoint& pos, BHtmlItem* item);
		BHtmlItem* findFloatItem(const BPoint& pos, BHtmlItem* item);
		BHtmlItem* itemOfId(BHtmlItem* item, const BString& id);

		void slotHeadChanged(BObject* object, const BValue& value);
		void slotBodyChanged(BObject* object, const BValue& value);

	public:
		BHtmlWidget*			boss;
		BHolder<BXmlNode>		htmlNode;
		BHolder<BXmlNode>		headNode;
		BHtmlItemHolder			bodyItem;
		BArray<BHtmlItemHolder>	floatItems;
		BString					fileName;
		BReal					blinkTick;
		BReal					blinkTime;
		bool					blinkShown;
		bool					editable;
		bool					autoTitle;
		SelectMode				selectMode;
		BHolder<IHtmlStyle>		htmlStyle;

		bool					dirty;
		bool					dirtyHead;
		bool					dirtyResource;
		bool					dirtyStyle;
		bool					editing;

		BHtmlItem*				hoveredItem;
		int						hoverIndex;
		bool					pressed;
		BHtmlItem*				pressedItem;
		int						pressedIndex;
		BPoint					pressPoint;
		BArray<const BFont*>	fontStack;
		BArray<BHtmlItem*>		selectedItems;
		BArray<BHtmlItem*>		visualItems;
	};
}

#endif
